<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/14
 * Time: 15:56
 */

namespace app\api\controller\v1;
use app\api\validate\TestValidate;
use app\lib\exception\BannerMissException;
use app\lib\exception\BaseException;
use app\lib\exception\ParamersException;
use think\Controller;
use app\api\model\Banner as BannerModel;
use think\Exception;
use think\Log;

/**
 * Class Banner
 * @package app\api\controller\v1
 */
class Banner extends Controller
{
    /**
     * 获取指定banner的指定id
     * @$id banner的id号
     * @url banner/:id
     * @http get
     *
     */
    public  function getBanner($id)
    {
       $banner = BannerModel::with(['item', 'item.img']) -> find($id);
       return $banner -> hidden(['update_time', 'item.id']);
    }

    /**
     * @param $id
     * @throws Exception
     * @throws ParamersException
     */
    public function getMessage($id)
    {
            $data['name'] = 'name';
            $data['id'] = $id;
            $result = Validate('TestValidate') -> check($data);
            if(!$result) {
                $e = new ParamersException([
                    'msg' => Validate('TestValidate')->getError(),
                    'code' => '400',
                ]);
                throw $e;
            }
            echo 'hello';
    }

}